package de.uni_saarland.coli.doclists.index.filesystem;

/**
 * 
 * @author stefan
 * 
 *         Stores the DiscList's byte array infos
 */
public class FileIndexEntry implements IToBytes {
	/**
	 * start in file
	 */
	private long start;

	/**
	 * Number of bytes
	 */
	private int length;

	/**
	 * Constructor
	 * 
	 * @param start
	 *            the start position in the file
	 * @param length
	 *            the data length in byte
	 */
	public FileIndexEntry(long start, int length) {
		this.start = start;
		this.length = length;
	}

	/**
	 * Constructor. length = byte array length start = 0
	 * 
	 * @param bytes
	 *            a byte array
	 */
	public FileIndexEntry(byte[] bytes) {

		this.start = FilesystemHelper.getLongFromByteArray(bytes, 0);

		this.length = FilesystemHelper.getIntFromByteArray(bytes, 8);
	}

	@Override
	public byte[] toBytes() {
		byte[] bytes = new byte[12];

		FilesystemHelper.addLongToByteArray(bytes, this.start, 0);
		FilesystemHelper.addIntToByteArray(bytes, this.length, 8);

		return bytes;
	}

	/**
	 * Returns the start position.
	 * 
	 * @return the start position
	 */
	public long getStart() {
		return start;
	}

	/**
	 * Sets the start position.
	 * 
	 * @param start
	 */
	public void setStart(long start) {
		this.start = start;
	}

	/**
	 * Returns the data's length.
	 * 
	 * @return the length
	 */
	public int getLength() {
		return length;
	}

	/**
	 * Returns the data's length.
	 * 
	 * @param length
	 *            the length
	 */
	public void setLength(int length) {
		this.length = length;
	}

	@Override
	/**
	 * Does nothing.
	 */
	public void setListIDX(int idx) {
	}

	@Override
	/**
	 * Returns always 0.
	 */
	public int getListIDX() {
		return 0;
	}

	@Override
	/**
	 * Does nothing.
	 */
	public void setDistList(DiscList list) {
	}

}
